package com.ruoyi.finance.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.finance.domain.FixedAsset;
import com.ruoyi.finance.service.IFixedAssetService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 固定资产Controller
 * 
 * @author 李伟
 * @date 2025-03-06
 */
@RestController
@RequestMapping("/finance/asset")
public class FixedAssetController extends BaseController
{
    @Autowired
    private IFixedAssetService fixedAssetService;

    /**
     * 查询固定资产列表
     */
    @PreAuthorize("@ss.hasPermi('finance:asset:list')")
    @GetMapping("/list")
    public TableDataInfo list(FixedAsset fixedAsset)
    {
        startPage();
        List<FixedAsset> list = fixedAssetService.selectFixedAssetList(fixedAsset);
        return getDataTable(list);
    }



    /**
     * 导出固定资产列表
     */
    @PreAuthorize("@ss.hasPermi('finance:asset:export')")
    @Log(title = "固定资产", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FixedAsset fixedAsset)
    {
        List<FixedAsset> list = fixedAssetService.selectFixedAssetList(fixedAsset);
        ExcelUtil<FixedAsset> util = new ExcelUtil<FixedAsset>(FixedAsset.class);
        util.exportExcel(response, list, "固定资产数据");
    }

    /**
     * 获取固定资产详细信息
     */
    @PreAuthorize("@ss.hasPermi('finance:asset:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(fixedAssetService.selectFixedAssetById(id));
    }

    /**
     * 新增固定资产
     */
    @PreAuthorize("@ss.hasPermi('finance:asset:add')")
    @Log(title = "固定资产", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FixedAsset fixedAsset)
    {
        return toAjax(fixedAssetService.insertFixedAsset(fixedAsset));
    }

    /**
     * 修改固定资产
     */
    @PreAuthorize("@ss.hasPermi('finance:asset:edit')")
    @Log(title = "固定资产", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FixedAsset fixedAsset)
    {
        return toAjax(fixedAssetService.updateFixedAsset(fixedAsset));
    }

    /**
     * 删除固定资产
     */
    @PreAuthorize("@ss.hasPermi('finance:asset:remove')")
    @Log(title = "固定资产", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fixedAssetService.deleteFixedAssetByIds(ids));
    }
}
